<#include "/WEB-INF/views/admin/common/layout/__mainlayout.html">
<#include "/WEB-INF/views/admin/common/__pagination.html">
<#assign navLink='admin:sys:settlement:list' />
<#assign pageCss>
<link rel="stylesheet" href="${ctx}/resource/validationengine/css/validationEngine.jquery.css">
</#assign>
<#assign pageScript>
<script type="text/javascript" src="${ctx}/resource/validationengine/js/jquery.validationEngine-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resource/validationengine/js/jquery.validationEngine.js"></script>
<script type="text/javascript">

$(document).ready(function() {
	laydate.render({
	    elem: '#search_date'
	    ,range: true
	  });
	$('#search_agentname').chosen();
	
	$("#batch_pay").click(function(){
		var selectedItem = [];
		$(".checkbox:checked").each(function(){
			selectedItem.push($(this).val());
		});
		var selected = selectedItem.join(",");
		if(selected != ''){
			$.ajax({
	            type: "GET",
	            url: "${ctx}/admin/sys/settlement/batchCheck?id="+selected,
	            dataType: "json",
	            success: function(data){
	            		if(data.success){
	            			layer.msg(data.errMsg, {
	            				icon : 1,
	            				time : 1000,
	            				end : function() {
	            					window.location.reload();
	            				}
	            			});
	            		}else{
	            			layer.msg(data.errMsg, {
	            				icon : 2,
	            				time : 1000,
	            				end : function() {
	            					window.location.reload();
	            				}
	            			});
	            		}
	                 }
	        });
		}else{
			layer.msg("please choose data", {
				icon : 2,
				time : 1000,
				end : function() {
					window.location.reload();
				}
			});
		}
		
	});
});

    function update(id) {
        layer.open({
            title: 'do settlement',
            type: 2,
            area: ['60%', '40%','no'],
            scrollbar: false,
            content: '${ctx}/admin/sys/settlement/update?id=' + id,
            end: function () {
                window.location.reload();
            }
        });
    	
    }

    function selectAll(checked) {
        $('.checkbox').prop('checked',checked);
    }

    function changeSelectAll(){
        var items = $('.checkbox');
        var allSelect = $('#AllSelectChk');
        var flag = 1;
        items.each(function (e,ele) {
            if(!$(ele).prop('checked')){
                flag = 0;
            }
        })
        allSelect.prop('checked',!!flag);
    }

</script>
</#assign>
<@mainlayout>
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-head am-cf">
                    <div class="widget-title  am-cf">settlement list</div>
                </div>
                <div class="widget-body  widget-body-lg am-fr">
                    <div class="am-u-sm-12 am-u-md-2 am-u-lg-5">
                        <div class="am-form-group">
                            <div class="am-btn-toolbar">
                                <div class="am-btn-group am-btn-group-xs">
                                    <@hasperm key='admin:sys:settlement:update'>
                                    <button id="batch_pay" type="button" class="am-btn am-btn-default am-btn-success">
                                        <span class="am-icon-paypal"></span> apply
                                    </button>
                                </@hasperm>
                            </div>
                    </div>
                </div>
            </div>
            <form action="${ctx}/admin/sys/settlement/list/" method="post">
            		<#if agents??>
            			<div class="am-u-sm-12 am-u-md-2">
								<div
									class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
									<select name="search_agentname" id="search_agentname">
										<option value="0">please select agent</option>
										<#list agents as agent>
											<#if search_agentname?? && search_agentname == agent.id>
												<option value="${agent.id}" selected="selected">${agent.name}</option>
											<#else>
												<option value="${agent.id}">${agent.name}</option>
											</#if>
										</#list>
									</select>
								</div>
							</div>
					</#if>
				<div class="am-u-sm-12 am-u-md-2">
							<div
								class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
								 <select name="search_status" id="search_status">
										<option value="-1">please select status</option>
										<#if search_status?? && search_status == 1>
											<option value="1" selected="selected">done</option>
										<#else>
											<option value="1" >done</option>
										</#if>
										<#if search_status?? && search_status == 0>
											<option value="0" selected="selected">new</option>
										<#else>
											<option value="0" >new</option>
										</#if>
										<#if search_status?? && search_status == 2>
											<option value="2" selected="selected">submitted</option>
										<#else>
											<option value="2" >submitted</option>
										</#if>
										<#if search_status?? && search_status == 3>
											<option value="3" selected="selected">refuse</option>
										<#else>
											<option value="3" >refuse</option>
										</#if>
									</select>
							</div>
						</div>
                <div class="am-u-sm-12 am-u-md-3">
							<div style="width:100%"
								class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
								<input type="text" class="am-form-field"  readonly name="search_date" value="${search_date}" id="search_date" placeholder="day">
								<span
									class="am-input-group-btn">
									<button
										class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search"
										type="submit"></button>
								</span>
							</div>
						</div>
            </form>
            <div class="am-scrollable-horizontal">
                <table class="am-table am-table-compact tpl-table-black am-text-nowrap am-table-hover "
                       id="example-r">
                    <thead>
                    <tr>
                        <th class=""><input type="checkbox"
                                                                      onclick="selectAll(this.checked)" id="AllSelectChk"/></th>
                        <th class="">ID</th>
                        <th class="">agentName</th>
                        <th class="">day</th>
                        <th class="">amount</th>
                        <th class="">status</th>
                        <th class="">create time</th>
                        <th class="">clean time</th>
                        <th class="">reason</th>
                       
                    </tr>
                    </thead>
                    <tbody>
                    <#list pageList.list as settlement>
                    <tr class="gradeX">
                        <td class=""><input type="checkbox" onclick="changeSelectAll()" class="checkbox" name="id"
                                                                      value="${settlement.id!}"/></td>
                        <td class="">${settlement.id!}</td>
                        <td class="">${settlement.agentName!}</td>
                        <td class="">${settlement.cleanDay!}</td>
                        <td class="">${settlement.amount!}</td>
                        <td class="">
                            <#if settlement.status == 1><font class="am-text-danger">done</font>
                            <#elseif settlement.status == 0><font class="am-text-success">new</font>
                            <#elseif settlement.status == 2><font class="am-text-danger">submitted</font>
                            <#elseif settlement.status == 3><font class="am-text-success">refuse</font>
                        </#if>
                        </td>
                        <td class="">${settlement.createTime!}</td>
                        <td class="">${settlement.cleanTime!}</td>
                        <td class="">${settlement.reason!}</td>
            </tr>
        </#list>
        <!-- more data -->
        </tbody>
        </table>
    </div>
    <@pagination page=pageList url='/admin/sys/settlement/list?search_status=${search_status}&search_date=${search_date}&search_agentname=${search_agentname}&search_id=${search_id}' />
</div>
</div>
</div>
</div>
</div>
</@mainlayout>

